package com.yphone.ui.my.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.yphone.ui.login.manager.LoginManager;
import com.yphone.ui.login.respone.UserInfo;
import com.yphone.ui.ysj.bean.RemoteConnectBean;
import com.yphone.utils.AccountUtils;
import com.zzkj.yunphone.R;

import java.util.ArrayList;
import java.util.List;

public class MyDevicesActivity extends AppCompatActivity {

    private ListView listview;
    private List<RemoteConnectBean> remoteConnectBeans;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_devices);
        initView();
        initData();
    }

    private void initData() {
        UserInfo userInfo = LoginManager.getInstance().getInfo();
        remoteConnectBeans = userInfo.remoteConnectBeans;
        listview.setAdapter(new BaseAdapter() {
            @Override
            public int getCount() {
                return remoteConnectBeans == null ? 0 : remoteConnectBeans.size();
            }

            @Override
            public Object getItem(int position) {
                return null;
            }

            @Override
            public long getItemId(int position) {
                return 0;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                RemoteConnectBean bean = remoteConnectBeans.get(position);
                if (convertView == null) {
                    convertView = View.inflate(MyDevicesActivity.this, R.layout.item_devices, null);
                    TextView tv_name = convertView.findViewById(R.id.tv_name);
                    TextView tv_time = convertView.findViewById(R.id.tv_time);
                    tv_name.setText(bean.getName());
                    tv_time.setText(MyDevicesActivity.this.getString(R.string.residue_time_str, AccountUtils.getDayAndHourTime(bean.timeHour)));
                }
                return convertView;
            }
        });
    }

    private void initView() {
        listview = findViewById(R.id.listview);
    }

    public static void toMyDevicesActivity(Context context) {
        Intent intent = new Intent(context, MyDevicesActivity.class);
        context.startActivity(intent);
    }

}
